package com.bootdo.wx.service.impl;

import cn.hutool.core.map.MapUtil;
import com.bootdo.common.utils.R;
import com.bootdo.wx.dao.OrderBackAdressDao;
import com.bootdo.wx.dao.OrderBackDao;
import com.bootdo.wx.dao.OrderOrderDao;
import com.bootdo.wx.domain.OrderBackAdressDO;
import com.bootdo.wx.domain.OrderBackDO;
import com.bootdo.wx.domain.OrderOrderDO;
import com.bootdo.wx.service.OrderBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



@Service
public class OrderBackServiceImpl implements OrderBackService {
	@Autowired
	private OrderBackDao orderBackDao;
	@Autowired
	private OrderBackAdressDao orderBackAdressDao;
	@Autowired
	private OrderOrderDao orderOrderDao;


	
	@Override
	public OrderBackDO get(String id){
		return orderBackDao.get(id);
	}
	
	@Override
	public List<OrderBackDO> list(Map<String, Object> map){
		return orderBackDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return orderBackDao.count(map);
	}
	
	@Override
	public int save(OrderBackDO orderBack){
		return orderBackDao.save(orderBack);
	}
	
	@Override
	public int update(OrderBackDO orderBack){
		return orderBackDao.update(orderBack);
	}
	
	@Override
	public int remove(String id){
		return orderBackDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return orderBackDao.batchRemove(ids);
	}

    @Override
    public OrderBackDO getByOrderId(String id) {
		OrderBackDO byOrderId = orderBackDao.getByOrderId(id);
		return byOrderId;

	}

    @Override
    public R getBackOrderInfo(Map<String, Object> paramMap) {
		String orderId = MapUtil.getStr(paramMap, "orderId");
		OrderBackDO orderBackDO = orderBackDao.getByOrderId(orderId);
		HashMap<Object, Object> objectObjectHashMap = MapUtil.newHashMap();
		objectObjectHashMap.put("orderBackDO",orderBackDO);
		OrderBackAdressDO orderBackAdressDO = orderBackAdressDao.getOrderBackAddress(orderId);
		objectObjectHashMap.put("orderBackAdressDO",orderBackAdressDO);
		return R.ok().put("data",objectObjectHashMap);
    }

    @Override
    public R removeOrderBack(Map<String, Object> paramMap) {
		OrderOrderDO orderOrderDO = orderOrderDao.get(MapUtil.getStr(paramMap, "orderId"));
		OrderBackDO orderBackDO = orderBackDao.getByOrderId(orderOrderDO.getId());

		orderOrderDO.setId(orderBackDO.getOrderId());
		orderOrderDO.setStatus(4);
		orderOrderDO.setUpdateAt(new Date());
		orderOrderDao.update(orderOrderDO);
		orderBackDO.setDelFlag(1);
		orderBackDO.setUpdateAt(new Date());
		orderBackDao.update(orderBackDO);
		return R.ok();

	}

}
